<?php

namespace App\Http\Controllers\App;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Dictionary;

class DictionaryController extends Controller
{	
	/**
	 * 获取版本号
	 * @return [type] [description]
	 */
    public function version()
    {
    	$version = Dictionary::where('id', 1)->value('contents');

    	return self::json(['version'=> $version]);
    }

    /**
     * 获取数据字典
     * @return [type] [description]
     */
    public function data()
    {
    	$data = Dictionary::where('id', '<>', 1)->where('status', '<>', 0)->get();

    	$data = $this->getData($data);
    	
    	return self::json($data);
    }

    /**
     * 获取数据字典
     * @param  [type] $data [description]
     * @return [type]       [description]
     */
    private function getData( $data )
    {
    	$arr = [];

    	foreach ($data as $k => $v) {
    		$arr[$v['title']] = $v;
    	}

    	return $arr;
    }
}
